package com.whity.towerdefense.model;


import android.content.res.AssetManager;
import android.util.Log;

public class GameModel
{

	// =============================================================
	// Protected attributs
	
	protected static AssetManager 	ASSETS_MANAGER;
	protected static GameThread		GAME_THREAD;
	public static Level				LEVEL;
	
	// =============================================================
	// Private attributs
	
	// Constants
	private static final String 	TAG = "com.djm.test03.model";
	private static final String 	GAMES_PATH = "Gameplay/Levels";
	
	@SuppressWarnings("unused")
	private static GameState		m_State;		
	
	// =============================================================
	// Public functions :
	
	public GameModel(AssetManager p_AssetManager)
	{
		ASSETS_MANAGER = p_AssetManager;
		m_State = GameState.MAIN_MENU;
		LEVEL = null;
		GAME_THREAD = new GameThread();
	}
	
	public void LoadLevel(String p_GamePath)
	{
		try
		{
			LEVEL = new Level(GAMES_PATH + "/" + p_GamePath);
			m_State = GameState.ACTION_PHASE;
			
		}
		catch (Exception e)
		{
			Log.w(TAG, "Can't load game xml : " + GAMES_PATH + "/" + p_GamePath + "\nerror : " + e.toString());
			for(StackTraceElement elt : e.getStackTrace())
			{
				Log.w(TAG, "Stack : " + elt.toString());
			}
			System.exit(-1);
		}
	}
	
	public void StartLevel()
	{
		if(LEVEL != null)
		{
			GAME_THREAD.AddTickable(LEVEL);
			GAME_THREAD.StartThread();
		}
	}
	
	public void Pause()
	{
		GAME_THREAD.OnPause();
	}
	
	public void Resume()
	{
		GAME_THREAD.onResume();
	}
	
	// =============================================================
	
}
